﻿using DevExpress.XtraReports.UI;
using DevTeam;
using System;
using System.Data;

namespace ConfExpert.Forms.Rapor.Aksesuar
{
    public partial class xrDugmeBoyamaRaporu : DevExpress.XtraReports.UI.XtraReport
    {
        DataSet ds;

        public xrDugmeBoyamaRaporu()
        {
            InitializeComponent();   
        }

        public xrDugmeBoyamaRaporu(int AksesuarCikisTalebiId,int BrandId,string spName)
            : this()
        {
            ds = Session.DataManager.ExecuteDataSet(spName, AksesuarCikisTalebiId,BrandId);

            xrSubDugmeBoyama SubDugme = (xrSubDugmeBoyama)xrSub.ReportSource;
            SubDugme.fillTable(ds.Tables["Table2"]);

            //DataRelation FK_AksCikisTalebi_DugmeBoyama = new DataRelation("FK_AksCikisTalebi_DugmeBoyama",
            //  ds.Tables["Table"].Columns["AksesuarCikisTalebiId"],
            //  ds.Tables["Table1"].Columns["AksesuarCikisTalebiId"]);
            //ds.Relations.Add(FK_AksCikisTalebi_DugmeBoyama);

            BindDstoReport();

            xrTable10.BeforePrint+=xrTable10_BeforePrint;
        }        

        void BindDstoReport()
        {
            this.DataMember = "Table1";
            this.DataSource = ds;

            DataRow drHeader = ds.Tables[0].Rows[0];
            tcTarih.Text = DateTime.Now.ToShortDateString();

            tcMarka.Text = drHeader["Marka"].ToString();
            tcSezon.Text = drHeader["Sezon"].ToString();
            tcTedarikci.Text = drHeader["BoyanacakYer"].ToString();
            tcTalebiOlusturan.Text = drHeader["TalepEden"].ToString();
        }

        private void xrSub_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            //int a = Convert.ToInt32(GetCurrentColumnValue("KaufIdx"));
            ((xrSubDugmeBoyama)((XRSubreport)sender).ReportSource).Idx.Value =Convert.ToInt32(GetCurrentColumnValue("RN"));
        }

        private void xrTable10_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            xrTable10.HeightF = 250F;
            Detail.HeightF = 250F;
            int a = ds.Tables[2].Select("RN=" + GetCurrentColumnValue("RN").ToString()).Length;
            if (a > 2)
            {
                xrTable10.HeightF = a * 125;
            }
        }

        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            this.DataMember = "Table1";
            this.DataSource = ds;

            tcDugmeKodu.DataBindings.Add("Text", null, "Table1.DugmeKodu");
            tcRenk.DataBindings.Add("Text", null, "Table1.Renk");
            //tcDosyaNo.DataBindings.Add("Text", null, "Table1.DosyaNo");
        }

    }
}
